home *** CD-ROM | disk | FTP | other *** search
- Path: sunrise.gv.ssi1.com!news
- From: Mike Palmer <Mike.Palmer@tus.ssi1.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Will Java kill C++?
- Date: 2 Mar 1996 04:54:27 GMT
- Organization: Silicon Systems, Inc.
- Message-ID: <4h8ka3$4o8@atlas.tus.ssi1.com>
- References: <3134D499.653E@ix.netcom.com> <313613B2.136E@ksopk.sprint.com> <4h554t$9jk@netline-fddi.jpl.nasa.gov>
- NNTP-Posting-Host: pc259u.tus.ssi1.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 16bit)
-
- madler@alumni.caltech.edu wrote:
- >In <313613B2.136E@ksopk.sprint.com> Eric Williams wrote:
- >" Overloaded operators are just methods... you can implement identical
- >" functionality using "regular" methods.
- >
- >No you can't, since operators have varying levels of precedence, methods
- >don't. An arithmetic expression with just a few operations written using
- >methods is completely unreadable. It looks like LISP.
- >
- >mark
- >
-
- I think the point was that you don't need overloaded operators to, say,
- add two complex numbers together, multiply the result by a third, and
- so on. The programmer obviously has to consider the correct order of
- execution, and so on.
-
- You are absolutely correct, though, in that the result is unreadable.
- I have overloaded operators for many of my classes, especially strings
- and matrices, just because of the notational (and readable)
- convenience.
-
- Although I could use overloaded operators to create a language that
- only I understand, if they are used in an intelligent and judicious
- manner, they can enhance the readability of code significantly, even
- for someone who doesn't know beans about your classes.
-
- For example, when I show the code fragment:
-
- Matrix A, B, C;
- ...
- A = A * B + C;
-
- to most programmers, they can immediately tell what is happening,
- whereas
-
- Matrix A, B, C;
-
- Matmult(A,B,A);
- MatAdd(A,C,A);
-
- wouldn't be nearly so obvious, even though the function is the same.
-
- So, my point is that when used intelligently, overloaded operators can
- be a useful tool, and can be used to create code that others can read
- and understand better than if you didn't have them.
-
- -- Mike --
-
-